package run;
import java.util.Random;

import processing.core.PApplet;

public class SandPainter {

  float p;
  int c;
  float g;
  
  public SandPainter(PApplet ap) {
	  p = ap.random(256);
	  c = (int) ap.random(256);
	  g = ap.random(256);
  }
  
  public void render (float x, float y, float ox, float oy, PApplet ap) {
  
    // draw painting sweeps
    ap.stroke(ap.red(c),ap.green(c),ap.blue(c),28);
    ap.point(ox + (x-ox)*(float)Math.sin(p),oy+(y-oy)*(float)Math.sin(p));

    
    g+=ap.random(-0.050F,0.050F);
    float maxg = 0.22F;
    if (g < -1 *maxg) g= -1 * maxg;
    if (g > maxg) g= maxg;

    float w = g/5f;
    for ( int i = 0; i < 11; i++ ) {
      float a = 0.1F - i/110F;
      ap.stroke(ap.red(c/2),ap.green(c/5),ap.blue(c),256*a);
      ap.point(ox+(x-ox)*(float)Math.sin(p+(float)Math.sin(i*w)),oy+(y-oy)*(float)Math.sin(p + (float)Math.sin(i*w)));
      ap.point(ox+(x-ox)*(float)Math.sin(p-(float)Math.sin(i*w)),oy+(y-oy)*(float)Math.sin(p - (float)Math.sin(i*w)));
    }
  }
}

